import java.util.Random;


public class Deck {
	private Card deck[];
	private int actualLength;
	
	public Deck(){
		actualLength = 52;
		deck = new Card[actualLength];
		for (int i = 0; i < 4; i++){
			for (int j = 0; j < 13; j++){
				deck[(i*13)+j] = new Card( i, j );
			}
		}
		
	}
	
	/**
	 * Shuffle included cards
	 */
	public void shuffle() {
		//Knuth shuffle
		Random rnd = new Random();
		int place;
		Card temp = new Card();
		for (int k = 51; k > 0; k--){
			place = rnd.nextInt(51);
			temp = deck[k];
			deck[k] = deck[place];
			deck[place] = temp;
			temp = null;
		}
	}
	
	/**
	 * Removes the top card from the deck
	 * @return removed card
	 */
	public Card takeCard(){
		Card chosen = new Card();
		chosen = deck[actualLength-1];
		deck[actualLength - 1] = null;
		actualLength--;
		return chosen;
	}

	/**
	 * Returns number of cards in deck
	 * @return
	 */
	public int getCardsNumber() {
		return actualLength;
	}

}
